----------------------------------------------------------------------------------------------------------------------------------------------------
--[[
    巡之丘高中校服： Megurigaoka Private High School Uniform
    所有名为【胡桃】的少女都可以穿的衣服。耐久类型为矿工帽型，满耐久可以穿5天。穿戴时，体力系数a增加0.4，攻击系数增加0.6，获得120防暑。
    长柄突刺的倍率由2倍提升为3倍。【笔记：hutao_com_polearm_mastery】【注意：原始默认是2倍，本装备倍增系数1.5就行了】
]]--
----------------------------------------------------------------------------------------------------------------------------------------------------
---
    local assets =
    {
        Asset("ANIM", "anim/hutao_equipment_megurigaoka_private_high_school_uniform.zip"),
    }
----------------------------------------------------------------------------------------------------------------------------------------------------
-- 参数
    local MAX_FINITE_USES = 5*480           --- 最大使用次数

----------------------------------------------------------------------------------------------------------------------------------------------------
--- 玩家被攻击 event
    local function player_get_attacked(player,_table)
        --  hutao_debuff_undying_lich 
        if player:HasDebuff("hutao_debuff_undying_lich_sleep") or player:HasDebuff("hutao_debuff_undying_lich_after_wakeup") then
            return
        end
        player:AddDebuff("hutao_debuff_undying_lich","hutao_debuff_undying_lich")
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
---装备、脱下
    local function onequip(inst, owner)
        -----------------------------------------------------
        --- 检查tag
            if not owner:HasTag("hutao") then
                return
            end
        -----------------------------------------------------
        -- --- 灯光
        --     if inst.light_fx then
        --         inst.light_fx:Remove()
        --     end
        --     inst.light_fx = owner:SpawnChild("minerhatlight")
        -----------------------------------------------------
        --- 计时器
            if inst._finiteuses_task then
                inst._finiteuses_task:Cancel()
            end
            inst._finiteuses_task = inst:DoPeriodicTask(1,function()
                inst.components.finiteuses:Use()
            end)
        -----------------------------------------------------
        --- 属性配置
            inst:DoTaskInTime(0.1,function()
                if owner.components.hutao_com_physical_power then
                    owner.components.hutao_com_physical_power:AddModulus(inst,0.4)
                end
                if owner.components.combat then
                    owner.components.combat.externaldamagemultipliers:SetModifier(inst,1+0.6)
                end
                if owner.components.hutao_com_polearm_mastery then
                    owner.components.hutao_com_polearm_mastery:SetSpikeModifier(inst,3/2)
                end
            end)
        -----------------------------------------------------
        --- 被攻击事件监听
            inst:ListenForEvent("attacked",player_get_attacked,owner)
        -----------------------------------------------------
        --- 
            owner.AnimState:OverrideSymbol("arm_lower","hutao_equipment_megurigaoka_private_high_school_uniform","arm_lower")
            owner.AnimState:OverrideSymbol("arm_upper","hutao_equipment_megurigaoka_private_high_school_uniform","arm_upper")
            owner.AnimState:OverrideSymbol("torso","hutao_equipment_megurigaoka_private_high_school_uniform","torso")
        -----------------------------------------------------
    end

    local function onunequip(inst, owner)
        -----------------------------------------------------
        --- 灯光
            if inst.light_fx then
                inst.light_fx:Remove()
                inst.light_fx = nil
            end
        -----------------------------------------------------
        --- 计时器
            if inst._finiteuses_task then
                inst._finiteuses_task:Cancel()
                inst._finiteuses_task = nil
            end
        -----------------------------------------------------
        --- 属性配置
            if owner.components.hutao_com_physical_power then
                owner.components.hutao_com_physical_power:RemoveModulus(inst)
            end
            if owner.components.combat then
                owner.components.combat.externaldamagemultipliers:RemoveModifier(inst)
            end
            if owner.components.hutao_com_polearm_mastery then
                owner.components.hutao_com_polearm_mastery:RemoveSpikeModifier(inst)
            end
        -----------------------------------------------------
        --- 被攻击事件监听
            inst:RemoveEventCallback("attacked",player_get_attacked,owner)
        -----------------------------------------------------
        --- 
            owner.AnimState:ClearOverrideSymbol("arm_lower")
            owner.AnimState:ClearOverrideSymbol("arm_upper")
            owner.AnimState:ClearOverrideSymbol("torso")
        -----------------------------------------------------
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 本体
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddSoundEmitter()
        inst.entity:AddNetwork()

        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank("hutao_equipment_megurigaoka_private_high_school_uniform")
        inst.AnimState:SetBuild("hutao_equipment_megurigaoka_private_high_school_uniform")
        inst.AnimState:PlayAnimation("idle")
        local scale = 1.5
        inst.AnimState:SetScale(scale,scale,scale)

        MakeInventoryFloatable(inst)

        inst.entity:SetPristine()

        --------------------------------------------------------------------------
        if not TheWorld.ismastersim then
            return inst
        end
        -----------------------------------------------------

        -----------------------------------------------------
        --- 物品
            inst:AddComponent("inspectable")
            inst:AddComponent("inventoryitem")
            -- inst.components.inventoryitem:ChangeImageName("cane")
            inst.components.inventoryitem.imagename = "hutao_equipment_megurigaoka_private_high_school_uniform"
            inst.components.inventoryitem.atlasname = "images/inventoryimages/hutao_equipment_megurigaoka_private_high_school_uniform.xml"
        -----------------------------------------------------
        --- 装备
            inst:AddComponent("equippable")
            inst.components.equippable:SetOnEquip(onequip)
            inst.components.equippable:SetOnUnequip(onunequip)
            inst.components.equippable.equipslot = EQUIPSLOTS.BODY
            inst.components.equippable.restrictedtag = "hutao"
        -----------------------------------------------------
        --- 耐久度
            inst:AddComponent("finiteuses")
            inst.components.finiteuses:SetMaxUses(MAX_FINITE_USES)
            inst.components.finiteuses:SetUses(MAX_FINITE_USES)
            inst.components.finiteuses:SetOnFinished(inst.Remove)
        -----------------------------------------------------
        --- 作祟
            MakeHauntableLaunch(inst)
        ---------------------------------------------------------
        --- 散热
            inst:AddComponent("insulator")
            inst.components.insulator:SetInsulation(120)
            inst.components.insulator:SetSummer()
        ---------------------------------------------------------
        return inst
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
return Prefab("hutao_equipment_megurigaoka_private_high_school_uniform", fn, assets)
